package com.itheima.stock.controller;

import com.itheima.stock.pojo.StockBusiness;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import com.itheima.stock.vo.resp.SecondResVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @author by itheima
 * @Date 2021/12/19
 * @Description
 */
@RestController
@RequestMapping("/api/quot")
@CrossOrigin
public class StockController {

    @Autowired
    private StockService stockService;
    @GetMapping("/stock/screen/second")
    public R<List<Map>> getStockSecond(String code) throws ParseException, IOException {
        System.out.println("code = " + code);
        return stockService.getStockSecond(code);
    }
    //个股最新分时行情
    @GetMapping("/stock/screen/second/detail")
    public R<Map> getrealTime(String code) {
        return stockService.getrealTimeNow(code);
    }
    /**
     * 个股主营业务查询接口
     * @param stockCode
     * @return
     */
    @GetMapping("/stock/describe")
    public R<Map> getStockBusinessShow(@RequestParam("code") String stockCode){
        return stockService.getStockBusinessShow(stockCode);
    }
    //获取周k
    @GetMapping("/stock/screen/weekkline")
    public R<List<Map>> getweeklychart(String code) {
        return stockService.getweeklyChart(code);
    }

    @RequestMapping("/external/index")
    public R<List<Map>> getduowai(){

        return stockService.getForeignMarket();
    }
    //股票模糊查询
    @GetMapping("/stock/search")
    public R<List<Map>> getBusiness(String searchStr) {
        return stockService.getlimitBusiness(searchStr);
    }
    /**
     * 单个个股日K 数据查询 ，可以根据时间区间查询数日的K线数据
     * @param stockCode 股票编码
     */
    @RequestMapping("/stock/screen/dkline")
    public R<List<Map>> getDayKLinData(@RequestParam("code") String stockCode){
        return stockService.getDayKLinData(stockCode);
    }


    /**
     * 个股分时行情
     * 查询单个个股的分时行情数据，查询时间周期是T日开盘到当前时间
     * @param sotckCode 个股编码
     * @return
     */
    @RequestMapping("/stock/screen/time-sharing")
    public R<List<Map>> getStockRtInfoByCode4EvrMinute(@RequestParam("code") String sotckCode){
        return stockService.getStockScreenMinuteSharing(sotckCode);
    }

    /**
     * 查询当前时间下股票的涨跌幅度区间统计功能
     * 如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询点
     * @return
     */
    @GetMapping("/stock/updown")
    public R<Map> getStockUpDown(){
        return stockService.getStockUpDownScope();
    }
    /**
     * 成交量对比
     * 沪深两市个股涨跌行情数据查询，查询T日分时成交量与T-1日分时成交量对比数据
     * 简言之，统计两市成交量在每分钟的之和的统计；
     * @return
     */
    @GetMapping("/stock/tradevol")
    public R<Map> getStockTravolCompare(){
        return stockService.getStockTravolCompare();
    }
    /**
     * 涨幅榜数据分页导出到excel
     * @param response 用于响应excel文件
     * @param page 当前页
     * @param pageSize 每页大小
     */
    @GetMapping("/stock/export")
    public void exPort(HttpServletResponse response, Integer page, Integer pageSize) throws IOException {
        this.stockService.exportStockExcel(response,page,pageSize);
    }

    /**
     * 涨停跌停数
     * 沪深两市涨跌停分时行情数据查询，查询T日每分钟的涨跌停数据
     * @return
     */
    @GetMapping("/stock/updown/count")
    public R<Map> getStockUpDownCount(){
        return stockService.getStockUpDownLimitCount();
    }
    /**
     * 沪深两市个股行情列表查询 ,以时间顺序和涨幅排序分页查询
     * @param page 当前页
     * @param pageSize 每页大小
     * @return
     */
    @GetMapping("/stock/all")
    public R<PageResult> getStockAll(Integer page, Integer pageSize){
        return stockService.getStockAll(page,pageSize);
    }
    /**
     * 涨幅榜
     * 沪深两市个股涨幅分时行情数据查询，以时间顺序查询前10条数据
     * @return
     */
    @GetMapping("/stock/increase")
    public R<List<Map>> getStockIncrease(){
        return stockService.getStockIncrease();
    }
    @GetMapping("/sector/all")
    public R<List<Map>> getSectorAll(){
        return stockService.getSectorAllLimit();
    }
    /**
     * 获取国内最新大盘指数
     * @return
     */
    @GetMapping("/index/all")
    public R<List<Map>> getInnerStockMarket(){
        return stockService.getInnerStockMarket();
    }

    @GetMapping("/stock/business/all")
    public List<StockBusiness> getAllBusiness(){
        return stockService.getAllStockBusiness();
    }
}    